class Solution(object):
    def threeSumSmaller(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        n = len(nums)
        if n < 3:
            return 0
        count = 0
        nums.sort()
        for i in range(n - 2):
            j = i + 1
            k = n - 1
            while j < k:
                if nums[i] + nums[j] + nums[k] < target:
                    count += (k - j)
                    j += 1
                else:
                    k -= 1
        return count


data = Solution()
nums = [-2, 0, 1, 3, 5, 7, -4, -2]
target = 2
print(data.threeSumSmaller(nums, target))